<template>
  <div>
    <!-- 导航栏 -->
    <van-nav-bar
      fixed
      placeholder
      title="问答"
      left-arrow
      @click-left="onClickLeft"
    />
    <!-- 主体内容 -->
    <div
      class="main-body"
      width:20px
      border-radius:5px
    >
      <!-- 内容 -->
      <div
        v-for="(item, i) in data"
        id="content"
        :key="i"
      >
        <!-- 左侧文字 -->
        <div id="content-left">
          <div class="content-title">{{ item.title }}</div>
          <div class="title-text">
            <span>赞同 {{ item.likeCount > 999 ? "999+" : item.likeCount }}</span>
            <span>评论{{ item.commentCount > 999 ? "999+" : item.commentCount }}</span>
            <span>{{ time }}</span>
          </div>
        </div>
        <!-- 右侧图片 -->
        <div class="pic" />
      </div>
    </div>
  </div>
</template>

<script>
import moment from 'moment';
export default {
  name: 'QaPage',
  data() {
    return {
      data: new Array(100)
        .fill(0)
        .map(() => ({
          // 标题
          title: '作为IT行业的过来人,你有什么话相对后辈说的？？？？？？？？？',
          // 点赞数 超过999显示为999+
          likeCount: 1234,
          // 评论数 超过999显示为999+
          commentCount: 555,
          // 发布时间
          pubTimestamp: 1658482134742,
          // 缩略图
          thumbSrc: 'https://pic1.zhimg.com/80/v2-8e77b2771314f674cccba5581560d333_xl.jpg?source=4e949a73',
        })),
      time: moment(1658482134742).fromNow(),
    };
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
  },
};
</script>

<style lang="less">
  .main-body {
    padding: 0 20px;
    height: calc(100% - 46px);
    overflow: auto;
    #content {
      display: flex;
      align-items: round;
      margin-top: 30px;
      padding-bottom: 20px;
      border-bottom: 1px solid #aaa;

      #content-left {
        width: 60%;
        margin-right: 20px;

        .title-text {
          color: #aaa;
          font-size: 14px;
        }

        .title-text span {
          margin: 0 4px;
        }

        .content-title {
          margin-bottom: 8px;
          overflow: hidden;
          -webkit-line-clamp: 2;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-box-orient: vertical;
        }
      }

      .pic {
        width: 25%;
        height: 70px;
        border-radius: 4px;
        background: url("https://pic1.zhimg.com/80/v2-8e77b2771314f674cccba5581560d333_xl.jpg?source=4e949a73");
        background-size: cover;
      }
    }
  }
</style>
